import { app } from '../../../../../../../../app/app';
import { EcsSystem } from '../../../../../../../../pkg-export/@gamex/cc-ecs';

/** 定义敌机组合刷新时间 */
const combinations = [
    {
        type: 0,
        interval: 1,
    },
    {
        type: 1,
        interval: 2.5,
    },
]
export class EnemySystem extends EcsSystem {
    /** 每10秒更换一次敌机组合 */
    private combinationInterval = 10;
    private interval = combinations[0].interval;

    /** 当前敌机组合 */
    private combinationIndex = 0;

    protected execute(dt: number): void {
        this.combinationInterval -= dt;
        if (this.combinationInterval <= 0) {
            this.combinationIndex = (this.combinationIndex + 1) % combinations.length;
            this.combinationInterval = 10;
            this.interval = combinations[this.combinationIndex].interval;
        } else {
            this.interval -= dt;
        }
        
        if (this.interval > 0) return;
        this.interval = combinations[this.combinationIndex].interval;

        app.controller.game.enemy(combinations[this.combinationIndex].type);
    }
}

